package com.tedu.user.controller;

import com.tedu.common.response.JsonResult;
import com.tedu.user.pojo.dto.UserQuery;
import com.tedu.user.pojo.vo.UserViolationRecordVO;
import com.tedu.user.pojo.vo.UserInfoVO;
import com.tedu.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/p1/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/select")
    public JsonResult selectUser(UserQuery userQuery) {
        log.debug("查询用户信息-入参：{}", userQuery);
        List<UserInfoVO> userInfoVOList = userService.selectUserInfo(userQuery);
        log.debug("查询用户信息-入参：{}，出参：{}", userQuery, userInfoVOList);
        return JsonResult.ok(userInfoVOList);
    }

    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updateStatus(
            @PathVariable Integer userId, @PathVariable String status) {
        log.debug("修改用户状态入参：{}，{}", userId, status);
        userService.updateStatus(userId, status);
        return JsonResult.ok();
    }

    @GetMapping("/violation/details")
    public JsonResult selectViolationRecordByUserId(@RequestParam Integer userId){
        log.debug("查询违规详情-入参：{}",userId);
        List<UserViolationRecordVO> list = userService.selectViolationRecordByUserId(userId);
        return JsonResult.ok(list);
    }
}
